<%@ page contentType="text/html;charset=UTF-8" %>

<html>
<head>
	<title>稿件新增/修改</title>
	
	<%@ include file="/common/meta.jsp" %>
    <%@ include file="/common/import.jsp" %>
    <script type="text/javascript" src="${ctx}/js/easyui/extendvalidate.js"></script>
	<script src="${ctx}/js/uct/uct_dict.js"></script>
	<script type="text/javascript" src="${ctx}/js/uct/uct_form.js"></script>
    <script type="text/javascript" src="${ctx}/js/uct/date.js"></script>
	<script type="text/javascript" src="${ctx}/js/zbxtools.js"></script>
	
	<script type="text/javascript" charset="utf-8" src="${ctx}/js/ueditor/ueditor.config.js"></script>
	<script type="text/javascript" charset="utf-8" src="${ctx}/js/ueditor/ueditor.all.min.js"> </script>
	<script type="text/javascript" src="${ctx}/js/ueditor/lang/zh-cn/zh-cn.js" ></script>
	<script type="text/javascript" src="${ctx}/js/strUtil.js" ></script>

	<script>

	$(function(){
		//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
		var ue = UE.getEditor('editor');
		var ueWin = "";
		/**	$('#manuscriptSaveForm').form({
		    onSubmit:function(){
		    	$("#content").html(UE.getEditor('editor').getContent());
		    	//alert($("#content").val());
		    	if($("#fileUpText_2").val()==""){
					$("#redirect_Url").val($("#redirectUrl").val());
				}else{
					$("#redirect_Url").val($("#fileUpText_2").val());
				}
		    	var checkFlag =  $(this).form('validate');
		    	if(checkFlag && confirm("确认提交内容吗？")){
		    		return true;
		    	}
		    	return false;
		    },
		    success:function(data){
		    	var result = jQuery.parseJSON(data);
		    	alert(result);
		    	if(result.flag=='T'){
		    		layer.alert('操作成功', {
		    			offset: '100px',closeBtn: 0
		    			}, function(){
		    				 var url = "${ctx}/wcm/manuscript/list.action?toPage=artice&channelId=${param.channelId}";
		    				 window.location.href=url;
		    			});
		    	}else{
		    		$.messager.alert('提交结果', result.msg, 'info');
		    	}        
		    }
		});**/
	}) ;
	
	function _submit(){
		$("#content").val(UE.getEditor('editor').getContent());
    	//alert($("#content").html());
    	if($("#fileUpText_2").val()==""){
			$("#redirect_Url").val($("#redirectUrl").val());
		}else{
			$("#redirect_Url").val($("#fileUpText_2").val());
		}
    	if(strUtil.isNull($("#title").val())){
    		alert("请输入标题");
    		return false;
    	}
    	var memoContent = $("#memo").val();
    	if(memoContent!="" && memoContent.length>200){
    		alert("简介内容太多，请不要超过200。");
    		return false;
    	}
    	var checkFlag =  $(this).form('validate');
    	if(checkFlag && confirm("确认提交内容吗？")){
    	}else{
    	   return false;
    	}
		$.ajax({
		    type:'post',
		    url:'${ctx}/wcm/manuscript/save.action',
		    data:$("#manuscriptSaveForm").serialize(),
		    dataType:'json',
		    success: function(myData){
		    	if(myData.flag=='T'){
		    		layer.alert('操作成功', {
		    			offset: '100px',closeBtn: 0
		    			}, function(){
		    				 var url = "${ctx}/wcm/manuscript/list.action?toPage=artice&channelId=${param.channelId}";
		    				 window.location.href=url;
		    			});
		    	}
		  	}
		});	
	}

	$.extend($.fn.validatebox.defaults.rules, {
    minLength: {
        validator: function(value, param){
            return value.length >= param[0];
        },
        message: 'Please enter at least {0} characters.'
    }
});
	

</script>

<body>	

<div id="tip"></div>
	<form id="manuscriptSaveForm" name="manuscriptSaveForm" method="post" action="${ctx}/wcm/manuscript/save.action">
	    <input type="hidden" name="formToken" id="formToken" value="${formToken}">
		<input type="hidden" name="channelId" id="channelId" value="${item.channelId}"/>
		<input type="hidden" name="manuscriptId" id="manuscriptId" value="${item.manuscriptId}"/>
		<input type="hidden" name="channelCode" id="channelCode" value="${item.channelCode}"/>
		<input type="hidden" name="redirectUrl" id="redirect_Url">
		<table class="tab_info" width="100%">
			<tr >
				<th>所属栏目<span style="color:red;" >*</span></td>
				<td>${channelName}	</td>
				<th>信息来源</th>
				<td>
				<input id="articeSource" name="articeSource"  value="${item.articeSource}" 
				class="easyui-validatebox" size="50"  missingMessage="请输入稿件关键字" />
				</td>
			</tr>
			<tr>
				<th>标　　题<span style="color:red;" >*</span></th>
				<td colspan="3">
				<input id="title" name="title"  value="${item.title}" 
				class="easyui-validatebox" style="width:700px;" required="true" maxlength="60" size="80"  missingMessage="请输入稿件标题" placeholder="必填项，请输入标题"  />
				</td>
			</tr>
			<tr>
				<th>副 标 题</th>
				<td>
				<input id="subTitle" name="subTitle"  value="${item.subTitle}" 
				class="easyui-validatebox" size="50"  missingMessage="请输入稿件副标题"  />
				</td>
				<!-- 
				<th>短 标 题</th>
				<td>
				<input id="shortTitle" name="shortTitle"  value="${item.shortTitle}" 
				class="easyui-validatebox" size="50"  missingMessage="请输入稿件短标题" />
				</td>
				 -->
				<th>关 键 字</th>
				<td>
				<input id="keyword" name="keyword"  value="${item.keyword}" 
				class="easyui-validatebox" size="50"  missingMessage="请输入稿件关键字" />
				</td>
			</tr>
			<tr style="display:none;">
				<th>类　　型</th>
				<td>
				<select id="type" name="type" style="width:183px;" onchange="showText()">
				<option value="1" selected="selected">普通稿件</option>
				<option value="2" >链接稿件</option>
				</select>
				</td>
				<th>是否加密</th>
				<td>
				<input type="radio" name="isEncrypted" id="isEncrypted_1" value="1" />是
				<input type="radio" name="isEncrypted"  id="isEncrypted_0" value="0" checked="checked" />否
				</td>
			</tr>	
			<tr id="artice_url">
			    <th>链接地址<span style="color:red;" >*</span></th>
				<td colspan="3"><input id="redirectUrl" value="${item.redirectUrl }" size="102" />  <span style="color:red;" >如：http://www.baidu.com/</span>
				</td>
			</tr>	
			<tr id="artice_url2">
			    <th>封面主图</th>
				<td colspan="3">
				<div id="fmtp">
					<c:if test="${!empty item.redirectUrl}">
        				<img id="fileUpText_2_showImg" src="${item.redirectUrl}" style="width:120px;height:80px;" />
        			</c:if>
        			<c:if test="${empty item.redirectUrl}">
        				<img id="fileUpText_2_showImg" src="${ctx}/images/def.jpg" style="width:120px;height:80px;" />
        			</c:if>
		        	<label onclick="addUploadFile(2);" for='uploadFileInput' class="blbtn">选择图片</label>
					<label id='fileUpText_2_subbtn' onclick="$.toolsupload.uploadSubmit(this);" style='display:none;' class="fDef_Btnse" >开始上传</label>
					<input id='fileUpText_2' objId='' isSub='F' value="${item.redirectUrl}" type="hidden"/>
					<label id="fileUpText_2_msg" style="color:red;"></label>
					<a id="fileUpText_2_a" href="#" target="_bank"></a>
				</div>
				</td>
			</tr>
			<tr>
			    <th>简　　介</th>
				<td colspan="3"><textarea id="memo" rows="4" cols="130" name="memo">${item.memo }</textarea>
				</td>
			</tr>	
			<tr>
			    <th>文章内容详情：</th>
			</tr>	
			<tr id="artice_text">
			<td colspan="4">
            	<textarea id="content" style="width:0%;height:0px;display:none;" name="content"></textarea>
				<script id="editor" type="text/plain"  style="width:1000px;height:400px;">${item.manuscriptContent }</script>
			</td>
			</tr>
				<tr>
				<td colspan="4" style="text-align: center;">	
					<!-- input class="bluebtn" type="submit" value=" 提 交 "/ -->	
					<input class="bluebtn" type="button" onclick="_submit()" value=" 提 交 "/>	
					<c:if test="${1==param.flag}">
						<input class="bluebtn" type="button" onclick="history.go(-1)" value=" 返 回 "/>
					</c:if>
				</td>
			</tr>
			
		</table>
		<p style="height: 100px;">&nbsp;</p>
	</form>
</body>
</html>
<!-- 附件上传iframe元素 -->
<iframe name='uploadIframe' id='uploadIframe' frameborder='0' height='0' width='0'></iframe>
<div id="uploadIframeDefDiv" style="height:0px;" ></div>
	
<script type="text/javascript" src="${ctx}/js/tools-upload.js"></script>
<script>
$(function(){		
	$("#artice_url").hide();
	ZBXTools.initRadio("isEncrypted","${item.isEncrypted}");
	ZBXTools.initSelect("type","${item.type}");
});

function showText(){
    var objS = document.getElementById("type");
    var grade = objS.options[objS.selectedIndex].value;
	    if(grade=="2"){
	    	$("#artice_url").show();
	    	$("#artice_text").hide();
	    	$("#artice_url2").hide();
	    	$('#url').attr('required', true);
	    	$("#fileUpText_2").val("");
	    }else{
	    	$("#artice_url").hide();
	    	$("#redirectUrl").val("");
	    	$('#url').attr('required', false);
	    	$("#artice_text").show();
	    	$("#artice_url2").show();
	    }
   }
//附件相关服务配置
var myAttaServer = '${ctx}/';
var myAttaDomain = 'dwusoft.com';
	//回调函数保存信息入库(上传成功才会调用此方法)
function myBack(){
	
}
</script>